/*
day249
2020.5.3
*/ 
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {
		vector<int> A,B;
		help(root1,A);
		help(root2,B);
		
		vector<int> res;
		
		int i=0,j=0;
		while(i<A.size() && j<B.size())
		{
			while(i<A.size() && A[i]<=B[j])
			{
				res.push_back(A[i]);
				++i;
			}
			
			while(j<B.size() && A[i]>=B[j])
			{
				res.push_back(B[j]);
				++j;
			}
		}
		
		while(i<A.size())
		{
			res.push_back(A[i]);
			++i;
		}
			
		while(j<B.size())
		{
			res.push_back(B[j]);
			++j;
		}
		
		return res;
    }
    
    void help(TreeNode *root,vector<int> &vec)
    {
    	if(!root)
    	{
    		return ;
		}
		
		help(root->left,vec);
		vec.push_back(root->val);
		help(root->right,vec);
	}
};

int main()
{
	
	return 0;
 } 
